package com.pxmeta.admin.controller;

import cn.authing.core.auth.AuthenticationClient;
import cn.authing.core.mgmt.ManagementClient;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.pxmeta.admin.controller.resp.GetTokenResp;
import com.pxmeta.admin.controller.resp.TokenResult;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.core.redis.RedisCache;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(value = "认证授权",tags = "认证授权")
@RequiredArgsConstructor
@RequestMapping("/auth")
public class AuthController {
    private final AuthenticationClient authenticationClient;
    @GetMapping("/getToken")
    @SneakyThrows
    public AjaxResult getToken(@RequestParam String code){
        Object obj = authenticationClient.getAccessTokenByCode(code).execute();
        String str = JSONObject.toJSONString(obj);
        TokenResult resp = JSONObject.parseObject(str, TokenResult.class);
        return AjaxResult.success(resp);
    }
}
